package com.zoffy.catdiarybackend.model.vo;

import com.alibaba.fastjson2.JSON;
import com.baomidou.mybatisplus.annotation.TableField;
import com.zoffy.catdiarybackend.model.entity.Article;
import lombok.Data;

import java.util.Date;

@Data
public class ArticleVo {
    private Long id;

    /**
     * 标题
     */
    private String title;

    /**
     * 内容
     */
    private String content;

    /**
     * 描述
     */
    private String description;

    /**
     * 缩略图
     */
    private String picture;



    /**
     * 用户id
     */
    private Long userId;

    /**
     * 类型(Markdown/draw)
     */
    private String type;
    private String status;
    private Permissions permissions;

    /**
     * 创建时间
     */
    private Date createTime;
    public static ArticleVo obj2Vo(Article article){
        ArticleVo articleVo=new ArticleVo();
        articleVo.setId(article.getId());
        articleVo.setTitle(article.getTitle());
        articleVo.setContent(article.getContent());
        articleVo.setType(article.getType());
        articleVo.setDescription(article.getDescription());
        articleVo.setPicture(article.getPicture());
        articleVo.setUserId(article.getUserId());
        articleVo.setCreateTime(article.getCreateTime());
        articleVo.setStatus(article.getStatus());
        Permissions permissions = JSON.parseObject(article.getPermissions(),Permissions.class);
        permissions.setCollaborators(null);
        articleVo.setPermissions(permissions);
        return articleVo;
    }


    @TableField(exist = false)
    private static final long serialVersionUID = 1L;
}
